package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.TransportCatalog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * created by wangjunfu on 2021-02-24 15:59:32
 */
@Repository
public class TransportCatalogDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(TransportCatalogDao.class);

    public TransportCatalog insert(final TransportCatalog transportCatalog) {
        insert("TransportCatalog.insert", transportCatalog);
        return transportCatalog;
    }

    public Boolean updateInfoById(final TransportCatalog transportCatalog) {
        return update("TransportCatalog.updateInfoById", transportCatalog) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("TransportCatalog.updateInfoByQuery", query) > 0;
    }

    public TransportCatalog selectById(final Integer id, final Integer entId) {
        Query query = Query.noPage();
        query.put("id", id);
        query.put("entId", entId);
        return queryForObject("TransportCatalog.selectById", query);
    }

    public List<TransportCatalog> selectByQuery(final Query query) {
        return queryForList("TransportCatalog.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("TransportCatalog.countByQuery", query);
    }

    public Boolean deleteById(final Integer id, final Integer entId) {
        TransportCatalog transportCatalog = new TransportCatalog();
        transportCatalog.setDeleteFlag(1);
        transportCatalog.setId(id);
        transportCatalog.setEntId(entId);

        return update("TransportCatalog.updateInfoById", transportCatalog) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("TransportCatalog.deleteById", query) > 0;
    }
}